package com.cg.controller.announcement;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cg.controller.AbstractController;
import com.cg.entity.BaseComment;
import com.cg.service.impl.BaseCommentServiceImpl;
import com.cg.utils.Constant;
import com.cg.utils.Query;
import com.cg.utils.R;
import com.cg.utils.annotation.SysLog;

@RestController
@RequestMapping("/sys/comment")
public class CommentController  extends AbstractController{
	
	@Autowired
	BaseCommentServiceImpl baseCommentServiceImpl;
	/**
	 * 所有留言列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:comment:list")
	public R list(@RequestParam Map<String, Object> params){
		//只有超级管理员，才能查看所有管理员列表
		if(getUserId() != Constant.SUPER_ADMIN){
			params.put("createUserId", getUserId());
		}
		
		//查询列表数据
		Query query = new Query(params);
		
//		BaseComment comment=new BaseComment();
		List<BaseComment> commentList = baseCommentServiceImpl.queryList(query);
		int total = baseCommentServiceImpl.queryTotal(query);
		
		//PageUtils pageUtil = new PageUtils(userList, total, query.getLimit(), query.getPage());
		
		return R.success(total, "", commentList);
	}
	
	/**
	 * 获取评论信息
	 */
	@RequestMapping("/info")
	public R info(){
		return R.ok().put("comment", null);
	}
	
	/**
	 * 用户信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:comment:info")
	public R info(@PathVariable("id") Long id){
		BaseComment comment = baseCommentServiceImpl.queryObject(id);
		
		
		return R.ok().put("comment", comment);
	}
	
	
//	/**
//	 * 保存用户
//	 */
//	@SysLog("")
//	@RequestMapping("/save")
//	@RequiresPermissions("sys:user:save")
//	public R save(@RequestBody SysUserEntity user){
//		ValidatorUtils.validateEntity(user, AddGroup.class);
//		
//		user.setCreateUserId(getUserId());
//		sysUserService.save(user);
//		
//		return R.ok();
//	}
	
	/**
	 * 修改用户
	 */
	@SysLog("修改评论")
	@RequestMapping("/update")
	@RequiresPermissions("sys:comment:update")
	public R update(@RequestBody BaseComment comment){
		
//		comment.set(getUserId());
		baseCommentServiceImpl.update(comment);
		
		return R.ok();
	}
	
	/**
	 * 删除用户
	 */
	@SysLog("删除评论")
	@RequestMapping("/delete")
	@RequiresPermissions("sys:comment:delete")
	public R delete(@RequestBody Long[] ids){
		
		baseCommentServiceImpl.deleteBatch(ids);
		
		return R.ok();
	}
	
	
	

}
